//
//  UIButton+Extension.swift
//  WKweiBo
//
//  Created by 阿拉斯加的狗 on 15/12/6.
//  Copyright © 2015年 阿拉斯加的🐶. All rights reserved.
//

import UIKit

extension UIButton {

    convenience init(imageName: String,backImageName: String?){
        
        self.init()
        //设置图片
        setImage(UIImage(named: imageName), forState:UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        //设置背景图片
        if let backImageName = backImageName{
        
            setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
            setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        }
        
        
        sizeToFit()
    
    }

    convenience init(title: String, color: UIColor, imageName: String) {
    
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        
        setTitleColor(color, forState: UIControlState.Normal)
        
        setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        sizeToFit()
        
    }
    
    convenience init(title: String, fontSize:CGFloat, color: UIColor, imageName: String?, backColor: UIColor? = nil) {
        
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        
        setTitleColor(color, forState: UIControlState.Normal)
        
        if let imageName = imageName {
        
            setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        }
        
        //设置背景颜色
        backgroundColor = backColor
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
        
    }





}
